home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Oberon / examples.lha / Examples / Oberon0 / GraphicElems0.Mod < prev    next >
Encoding:
Text File  |  1994-06-16  |  2.6 KB  |  83 lines

  1. MODULE GraphicElems0;  (*HM Mar-25-92*)
  2. IMPORT OS, Texts0, Shapes0, GraphicFrames0, TextFrames0, Viewers0;
  3.  
  4. TYPE
  5.   Element* = POINTER TO ElemDesc;
  6.   ElemDesc* = RECORD (Texts0.ElemDesc)
  7.     orgX, orgY: INTEGER;
  8.     graphic: Shapes0.Graphic;
  9.   END;
  10.   UpdateFrame = POINTER TO UpdateFrameDesc;
  11.   UpdateFrameDesc = RECORD (GraphicFrames0.FrameDesc)
  12.     text: Texts0.Text;
  13.     e: Element
  14.   END;
  15.  
  16. VAR f: GraphicFrames0.Frame; (*reused within a text frame whenever a graphic
  17. element has to be redrawn*)
  18.  
  19. PROCEDURE (e: Element) Copy* (): Texts0.Element;
  20.   VAR res: Element;
  21. BEGIN NEW(res); res^ := e^; res.graphic := e.graphic.Copy(); RETURN res
  22. END Copy;
  23.  
  24. PROCEDURE (e: Element) Draw* (x, y: INTEGER);
  25. BEGIN
  26.   f.x := x; f.y := y; f.w := e.w; f.h := e.h; f.orgX := e.orgX; f.orgY := e.orgY;
  27. f.graphic := e.graphic;
  28.   f.Draw
  29. END Draw;
  30.  
  31. PROCEDURE (e: Element) HandleMouse* (f: OS.Object; x, y: INTEGER);
  32.   VAR v: Viewers0.Viewer; menu: TextFrames0.Frame; cont: UpdateFrame; buttons:
  33. SET;
  34. BEGIN REPEAT OS.GetMouse(buttons, x, y) UNTIL buttons = {};
  35.   menu := TextFrames0.NewMenu("", "Viewers0.Close  Viewers0.Copy  GraphicElems0.Update");
  36.   NEW(cont); cont.graphic := e.graphic;
  37.   cont.orgX := e.orgX + 10; cont.orgY := e.orgY + 10;
  38.   cont.text := f(TextFrames0.Frame).text; cont.e := e;
  39.   v := Viewers0.New(menu, cont)
  40. END HandleMouse;
  41.  
  42. PROCEDURE (e: Element) Load* (VAR r: OS.Rider);
  43. BEGIN e.Load^ (r);
  44.   r.ReadInt(e.orgX); r.ReadInt(e.orgY);
  45.   NEW(e.graphic); Shapes0.InitGraphic(e.graphic); e.graphic.Load(r)
  46. END Load;
  47.  
  48. PROCEDURE (e: Element) Store* (VAR r: OS.Rider);
  49. BEGIN e.Store^ (r); r.WriteInt(e.orgX); r.WriteInt(e.orgY); e.graphic.Store(r)
  50. END Store;
  51.  
  52. PROCEDURE Insert*;
  53.   VAR e: Element; f: TextFrames0.Frame;
  54. BEGIN
  55.   IF Viewers0.focus # NIL THEN f := Viewers0.focus(TextFrames0.Frame);
  56.     IF (f # NIL) & (f.caret.pos >= 0) THEN
  57.       NEW(e); e.w := 12; e.h := 12; e.dsc := 0; e.orgX := 0; e.orgY := 0;
  58.       NEW(e.graphic); Shapes0.InitGraphic(e.graphic);
  59.       f.text.SetPos(f.caret.pos); f.text.WriteElem(e)
  60.     END
  61.   END
  62. END Insert;
  63.  
  64. PROCEDURE Update*;
  65.   VAR v: Viewers0.Viewer; f: UpdateFrame; e: Element; m: Texts0.NotifyReplMsg;
  66. x, y: INTEGER; pos: LONGINT;
  67. BEGIN v := Viewers0.ViewerAt(TextFrames0.cmdFrame.y); f := v.cont(UpdateFrame);
  68.   e := f.e; pos := f.text.ElemPos(e);
  69.   IF pos < f.text.len THEN
  70.     f.graphic.GetBox(x, y, e.w, e.h);
  71.     e.graphic := f.graphic; e.orgX := - x ; e.orgY := - y;
  72.     m.t := f.text; m.beg := pos; m.end := pos + 1; Viewers0.Broadcast(m)
  73.   END
  74. END Update;
  75.  
  76. PROCEDURE Init;
  77.   VAR g: Shapes0.Graphic;
  78. BEGIN NEW(g); Shapes0.InitGraphic(g); f := GraphicFrames0.New(g)
  79. END Init;
  80.  
  81. BEGIN Init
  82. END GraphicElems0.
  83.